package com.snopy.utils;

/**
 * @author snopy
 * @version 1.0.0
 * @classname BinaryNumUtils
 * @description
 * @email 77912204@qq.com
 * @date 2022/03/18 12:49
 */
public class BinaryNumUtils {
    /**
     * @Description 二进制展示
     * @param num:
     * @return: java.lang.String
     * @Date 2022-03-18
     * @Author txl77912204@gmail.com
     **/
    public static String toBinaryStr(int num){

        StringBuilder s = new StringBuilder();
        int len = Integer.numberOfLeadingZeros(num);
        for (int i = 0;i<len;i++){
            s.append("0");
        }
        if (num==0){
            return s.toString();
        }
        return s.append(Integer.toBinaryString(num)).toString();
    }
}
